package com.longrise.android.byjk.plugins.login;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.longrise.android.byjk.R;
import com.longrise.common.utils.PrintLog;
import com.longrise.android.byjk.widget.view.CustomerServiceGuideView;


/**
 * Created by callxkj on 16/5/30.
 * 蒙板效果
 */
public class TipsActivity extends Activity implements View.OnClickListener {

    private static final String TAG = "TipsActivity";
    private ImageView mIv;
    private int mType;
    private RelativeLayout mRlrootview;
    private int[] mLocations;
    // public static final int MINE_TIPS = 12;  //设置
    public static final int BYSHARE_TIPS = 13; //保易网分享
    public static final int HOME_FRAGMENT = 14; //首页新增的8个按钮的提示
    private CountDownTimer mTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_tips);
        Intent intent = getIntent();
        mType = intent.getIntExtra("type", 0);
        mLocations = intent.getIntArrayExtra("location");
        initView();
        PrintLog.e(TAG, "mType: " + mType);
    }

    private void initView() {
        mRlrootview = (RelativeLayout) findViewById(R.id.tips_rootview);
        initEvent();
        mIv = (ImageView) findViewById(R.id.tips_iv);
        mIv.setScaleType(ImageView.ScaleType.FIT_XY);
        switch (mType) {
//            case 7:
//                mIv.setImageResource(R.drawable.page07);
//                break;
//
//            case 8: //题库
//                mIv.setImageResource(R.drawable.img1);
//                ViewGroup.LayoutParams layoutParams = mIv.getLayoutParams();
//                layoutParams.height = ScreenUnit.dip2px(this, 252);
//                layoutParams.width = ScreenUnit.dip2px(this, 266);
//                mRlrootview.setBackgroundColor(getResources().getColor(R.color.shadow));
//                mIv.setLayoutParams(layoutParams);
//                break;
//
//            case 10://资讯详情页面评论的提示
//                toShowCSGuideView(10);
//                break;
//
//            case 11://题库第二页日历提示
//                toShowCSGuideView(11);
//                break;
//            case MINE_TIPS: //我的12/26日添加的操作指引
//                toShowCSGuideView(MINE_TIPS);
//                break;
            case BYSHARE_TIPS: //保易网分享
                toShowCSGuideView(BYSHARE_TIPS);
                toCountdown();
                break;
            case HOME_FRAGMENT:  //首页新增的8个按钮的提示
                homeFragmentGuideView();
                break;
        }
    }

    private void initEvent() {
        mRlrootview.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tips_rootview:
                finish();
                overridePendingTransition(0, 0);
                break;
        }
    }

    /**
     * 客服的新手提示
     */
    private void toShowCSGuideView(int num) {
        mIv.setVisibility(View.GONE);
        CustomerServiceGuideView csview = new CustomerServiceGuideView(this);
//        if (num == 5) { //客服
//            csview.setCircleLocation(mLocations, CustomerServiceGuideView.GuideType.CUSTOMERSERVICE);
//        } else if (num == 10) { //资讯详情页
//            csview.setCircleLocation(mLocations, CustomerServiceGuideView.GuideType.NEWSDETAILCOMMENT);
//        } else if (num == 11) { //题库的日历
//            csview.setCircleLocation(mLocations, CustomerServiceGuideView.GuideType.TKCALENDAR);
//        } else if (num == MINE_TIPS) {
//            csview.setCircleLocation(mLocations, CustomerServiceGuideView.GuideType.MINE);
//        }else
        if (num == BYSHARE_TIPS) {
            csview.setCircleLocation(mLocations, CustomerServiceGuideView.GuideType.BYSHARE_TIPS);
        }
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        mRlrootview.addView(csview, layoutParams);
    }

    /**
     * 倒计时
     */
    private void toCountdown() {
        mTimer = new CountDownTimer(3000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {

            }

            @Override
            public void onFinish() {
                finish();
                overridePendingTransition(0, 0);
            }
        };
        mTimer.start();
    }

    /**
     * 首页新增的8个按钮的提示
     */
    private void homeFragmentGuideView() {
        mIv.setVisibility(View.GONE);
        mRlrootview.setClickable(false);
        mRlrootview.setOnClickListener(null);
        mRlrootview.setBackgroundColor(Color.parseColor("#EAEAEA"));
        View view = View.inflate(this, R.layout.item_guideview_homefragment, null);
        Button btknow = (Button) view.findViewById(R.id.guideview_homefragment_bt);
        mRlrootview.addView(view);
        btknow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                overridePendingTransition(0, 0);
            }
        });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            finish();
            overridePendingTransition(0, 0);
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mTimer != null) {
            mTimer.cancel();
            mTimer = null;
        }
    }
}
